package cn.edu.xmut.chen.zhlg.zhlg.vacancy.controller;

import cn.edu.xmut.chen.zhlg.common.HttpResult.Result;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.param.VacancyAddParam;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.param.VacancyPageSearchOtherParam;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.param.VacancyPageSearchParam;
import cn.edu.xmut.chen.zhlg.zhlg.vacancy.service.VacancyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/vacancy")
@Api("空缺岗位 API")
public class VacancyController {
    @Resource
    private VacancyService vacancyService;

    @RequestMapping(method = RequestMethod.POST, value = "/addVacancy")
    @ApiOperation(value = "添加新岗位", notes = "此方法用于向数据库添加一个新岗位")
    @ApiImplicitParam(name = "vacancyAddParam", value = "需要添加的空缺岗位对象", required = true, dataType = "VacancyAddParam")
    public Result createdVacancy(@RequestBody VacancyAddParam vacancyAddParam) {
        return Result.success("添加成功").data(vacancyService.create(vacancyAddParam));
    }

    @RequestMapping(method = RequestMethod.POST, value = "/save")
    @ApiOperation(value = "更新岗位", notes = "此方法用于更新岗位信息")
    @ApiImplicitParam(name = "vacancyAddParam", value = "需要更新的岗位对象", required = true, dataType = "VacancyAddParam")
    public Result saveVacancy(@RequestBody VacancyAddParam vacancyAddParam) {
        return Result.success("更新成功").data(vacancyService.save(vacancyAddParam));
    }

    @RequestMapping(method = RequestMethod.GET,value = "/page/search")
    @ApiOperation(value = "分页获取岗位列表", notes = "此方法用于分页获取岗位列表")
    @ApiImplicitParam(name = "vacancyPageSearchParam", value = "需要添加的空缺岗位对象", required = true, dataType = "page")
    public Result pageSearch(VacancyPageSearchParam vacancyPageSearchParam) {
        return Result.success("获取成功").data(vacancyService.pageSearch(vacancyPageSearchParam));
    }

    @RequestMapping(method = RequestMethod.GET,value = "/getDetail")
    @ApiOperation(value = "获取岗位详情", notes = "此方法用于获取一个岗位详情")
    @ApiImplicitParam(name = "id", value = "需要获取岗位对象", required = true, dataType = "Vacancy")
    public Result getOne(String id) {
        return Result.success("获取成功").data(vacancyService.getDetail(id));
    }

    @RequestMapping(method = RequestMethod.GET,value = "/page/getOther")
    @ApiOperation(value = "分页获取其他岗位列表", notes = "此方法用于分页获取其他岗位")
    @ApiImplicitParam(name = "id", value = "需要排除获取岗位对象", required = true, dataType = "page")
    public Result pageSearchOther(VacancyPageSearchOtherParam vacancyPageSearchOtherParam) {
        return Result.success("获取成功").data(vacancyService.getPageOther(vacancyPageSearchOtherParam));
    }

    @RequestMapping(method = RequestMethod.POST,  value = "/delete")
    @ApiOperation(value = "删除岗位", notes = "此方法用于删除岗位")
    @ApiImplicitParam(name = "id", value = "需要删除岗位对象", required = true, dataType = "Vacancy")
    public Result delete(@RequestBody String vacancyId) {
        return Result.success("删除成功").data(vacancyService.removeById(vacancyId));
    }
}
